<template>
  <div class="all-box">
    <div class="n-box1">
      <echarts2 id="echarts9" :option="optionN1" :styles="styles1"></echarts2>
    </div>
    <div class="n-box2">
      <echarts2 id="echarts91" :option="optionN3" :styles="styles1"></echarts2>
    </div>
  </div>
</template>

<script>
import echarts from "echarts";
import echarts2 from "@/components/echarts.vue";

export default {
  name: "Nice",
  props: {
    chartData: {
      type: Array,
      default: () => {
        return [];
        // return [1, 8, 6, 3];
      }
    },
    nameList: {
      type: Array,
      default: () => {
        // return ["一分部", "二分部", "三分部", "四分部"];
        return [];
      }
    },
    hChartData: {
      type: Array,
      default: () => {
        return [];
        // return [20, 25];
      }
    },
    hNameList: {
      type: Array,
      default: () => {
        // return [ "监测预警", '安质检查'];
        return [];
      }
    }
  },
  data() {
    var colors = ["#7cf317", "#d10eb1", "#4ddbff"];
    return {
      styles1: {
        width: "100%",
        height: "100%",
        margin: "0 auto"
      },
      optionN1: {
        barWidth: 10,

        // barGap:'80%',
        xAxis: {
          type: "category",
          // data: ["安全教育", "转发分享", "现场扫码", "系统推送"],
          data: this.nameList,
          // 去掉y轴坐标线
          axisLine: {
            show: false
          },
          axisTick: {
            show: false
          },
          // 设置字体
          axisLabel: {
            show: true,
            textStyle: {
              color: "#ffffff",
              fontSize: 12
            }
          }
        },

        series: [
          {
            type: "bar",
            // data: [600, 900, 1100, 700],
            data: this.chartData,
            itemStyle: {
              normal: {
                barBorderRadius: [3, 3, 0, 0],
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                  {
                    offset: 0,
                    color: "#39FBA4"
                  },
                  {
                    offset: 1,
                    color: "#27E0F7"
                  }
                ])
              }
            }
          }
        ],
        yAxis: [
          {
            type: "value",
            // max : 1200,
            // min: 400,
            splitNumber: 4,
            // 去掉刻度
            axisTick: {
              show: false
            },
            bottom: 10,
            // show : false,
            // 去掉y轴坐标线
            axisLine: {
              show: false
            },
            //网格样式
            splitLine: {
              show: true,
              lineStyle: {
                color: ["#0d1b4b"],
                width: 1,
                type: "solid"
              }
            },
            // 设置字体
            axisLabel: {
              show: true,
              textStyle: {
                color: "#ffffff",
                fontSize: 12
              }
            }
          }
        ],
        // 设置图标的位置
        grid: {
          x: 60,
          x2: 30,
          y:10,
          y2: 10,
          containLabel: true
        }
      },
      optionN3: {
        title: {
          text: '隐患来源统计',
          color:　'#fff',
          left: 5,
          textStyle: {
            color: '#fff',
            fontSize: 14
          }
        },
        barWidth: 10,
        yAxis: {
          type: "category",
          show: true,
          // 去掉y轴坐标线
          data: this.hNameList,
          axisLine: {
            show: false
          },
          axisTick: {
            show: false
          },
          // 设置字体
          axisLabel: {
            show: true,
            textStyle: {
              color: "#ffffff",
              fontSize: 12
            }
          }
        },

        series: [
          {
            name: "隐患",
            type: "bar",
            data: this.hChartData,
            itemStyle: {
              normal: {
                // normal:{
                //每个柱子的颜色即为colorList数组里的每一项，如果柱子数目多于colorList的长度，则柱子颜色循环使用该数组
                // color: function (params){
                //     var colorList = ['rgb(164,205,238)','rgb(42,170,227)','rgb(25,46,94)','rgb(195,229,235)'];
                //     return colorList[params.dataIndex];
                // }
                barBorderRadius: [0, 3, 3, 0],
                color: function(params) {
                  let colorList = [
                    new echarts.graphic.LinearGradient(0, 0, 1, 1, [
                      {
                        offset: 0,
                        color: "#FF6E02"
                      },
                      {
                        offset: 1,
                        color: "#FFFF00"
                      }
                    ]),
                    new echarts.graphic.LinearGradient(0, 0, 1, 1, [
                      {
                        offset: 0,
                        color: "#0017C2"
                      },
                      {
                        offset: 1,
                        color: "#53C8FF"
                      }
                    ])
                  ];
                  return colorList[params.dataIndex];
                }
              }
            }
          }
        ],
        xAxis: [
          {
            type: "value",
            // max : 1200,
            // min: 400,
            splitNumber: 4,
            // 去掉刻度
            axisTick: {
              show: false
            },
            // data: ["苹果","小米","华为","其他"] ,
            bottom: 10,
            // show : false,
            // 去掉y轴坐标线
            axisLine: {
              show: false
            },
            //网格样式
            splitLine: {
              show: true,
              lineStyle: {
                color: ["#0d1b4b"],
                width: 1,
                type: "solid"
              }
            },
            // 设置字体
            axisLabel: {
              show: true,
              textStyle: {
                color: "#ffffff",
                fontSize: 12
              }
            }
          }
        ],
               // 设置图标的位置
        grid: {
          x: 40,
          x2: 60,
          y: 40,
          y2: 10,
          containLabel: true
        }
      }
    };
  },
  components: {
    echarts2
  }
};
</script>
<style lang="scss">
.all-box {
  width: 100%;
  // height: 100%;
  height: calc(100% - 24px);
  .n-box1 {
    // background: pink;
    width: 100%;
    height: 60%;
  }
  .n-box2 {
    // background: pink;
    width: 100%;
    height: 40%;
  }
}
</style>